package wsem.utils;

import java.util.Map;



public class SparQLUtils {
	
	public static void findWithSparQL(String motcle){
		System.out.println(motcle);
		SparqlClient sparqlClient = new SparqlClient("localhost:8080/space");

        String query = "ASK WHERE { ?s ?p ?o }";
        boolean serverIsUp = sparqlClient.ask(query);
        if(serverIsUp){
        	System.out.println("Server is up");
        	findSynonyme(sparqlClient,motcle);
        }
	}
	
	
	  public static void findSynonyme(SparqlClient sparqlClient, String motcle){
		  	String parameter = motcle;
	    	String query = "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>"
	                + "PREFIX l:<http://www.semanticweb.org/clement/ontologies/2014/0/Ontologie-Balades#>"
	                + "\nSELECT ?other WHERE\n"
	                    + "{\n"
	                    + "?x rdfs:label '"+parameter+"'."
	                    + "OPTIONAL{?x rdfs:label ?other}. "
	                    + "}\n";
	            Iterable<Map<String, String>> results = sparqlClient.select(query);
	            System.out.println(query);
	            for (Map<String, String> result : results) {
	                System.out.println(result.get("other"));
	            }
	     
	    }

}
